package com.mo.sys.service.impl;


import com.mo.common.annotation.RequiredLog;
import com.mo.sys.dao.SysLogDao;
import com.mo.sys.pojo.SysLog;
import com.mo.sys.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


    @Transactional(readOnly = false,
            timeout = 60,
          rollbackFor = RuntimeException.class,
        //noRollbackFor =   不回滚
        isolation = Isolation.READ_COMMITTED
    )
    @Service
public class SysLogServiceImpl implements SysLogService {

    @Autowired
    private SysLogDao sysLogDao;

    @Transactional(readOnly = true)
    //@RequiredTime()
    @RequiredLog(operation = "*****日志查询")
    @Override
    public List<SysLog> findLogs(SysLog sysLog) {

        List<SysLog>list=sysLogDao.selectLogs(sysLog);

        return list;
    }



    @Async
    @Override
    public void savelogs(SysLog sysLog) {
        int rows=sysLogDao.insertLogs(sysLog);

    }



   // @Transactional  //注解描述事务，赋给事务属性
    @RequiredLog(operation = "删除日志***")
    @Override
    public int deleteById(Long... id) throws Exception {
    /*  for (int i = 0; i < id.length; i++) {
            if(i==1){
                 throw new Exception("删除失败");
                 //删除失败后事务整体回滚
            }
                    sysLogDao.deleteById(id[i]);
        }
        return 10;
        */

        int rows=sysLogDao.deleteById(id);
        return rows;

    }









   // @RequiredTime()
     @RequiredLog(operation = "日志查询查询")
    @Override
    public SysLog findById(Long id) throws Exception {
        SysLog log=sysLogDao.selectById(id);
        if(log==null){
            throw new Exception("记录可能已经不存在");
        }
        return log;
    }
}
